feat(intelligence): IaC からインフラリソースを検出(ADR-0016 D10)#449
Conversation
Terraform/OpenTofu の .tf から provider(AWS/Google 等)と resource(具体 サービス。aws_s3_bucket 等)を抽出し、kind=infra / signal_source=infra_declared として 3 層モデルへ投入する。当初「検討中/未採用」だった将来課題を機械検出に 限定して採用(D10)。表示名の human-in-the-loop 畳み込みは別 PR。 - skills/infra/: 正規表現ベースの Terraform parser を plugin 型で新設(依存なし) - skills/types.py: SKILL_KIND_INFRA / InfraResourceDeclaration を追加 - github_collector.py: 同一 tree(1 コール)から .tf を探索、.terraform 除外・ 深さ/件数キャップ・partial 伝播(D9 探索を流用) - skills/aggregator.py: _collect_infra を追加。provider/resource を別スキルで keep-all し、リポあたり 1 evidence にデデュープ - schemas/github_skill.py: description を拡張し generated.ts を再生成 - docs/adr/0016: D10 を追記、将来課題を格上げ・改訂履歴を更新 kind/signal_source/ecosystem は既存 String カラムの値域内のため migration 不要。 既存 language/package 検出・unique_skills・API 契約は不変。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ae3B21DsBFV7ev8SozSYt9
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR adds Terraform/OpenTofu infra resource detection to the GitHub skill pipeline, including new infra types, a parser registry, collector scanning with caps, aggregation into ChangesInfra skill detection pipeline
Estimated code review effort: 3 (Moderate) | ~30 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
backend/app/services/intelligence/github_collector.py (1)
182-212: 🚀 Performance & Scalability | 🔵 TrivialIaC fetch loop adds up to 30 more sequential round-trips per repo.
The new
.tffetch loop follows the existing manifest/source pattern of awaitingfetch_repo_fileone path at a time. Combined with the pre-existing manifest and source loops, a monorepo hitting all three caps could issue dozens of sequential HTTP calls per repo before moving to the next repository, adding to overall GitHub-link pipeline latency.Consider bounding concurrency (e.g.
asyncio.gatherwith a semaphore) for the fetch loops if link latency becomes a concern, while being mindful of GitHub secondary rate limits.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/app/services/intelligence/github_collector.py` around lines 182 - 212, The new IaC fetch loop in github_collector.py is still doing one await per path, which can add many sequential GitHub round-trips alongside the existing manifest and source loops. Update the fetch flow around fetch_repo_file, parse_infra, and the selected_infra iteration to use bounded concurrency (for example with asyncio.gather plus a semaphore) so multiple files can be fetched in parallel without exceeding rate-limit safeguards. Keep the existing selection caps and partial-tracking behavior intact while applying the same pattern consistently across the manifest, source, and infra fetch loops.backend/tests/test_github_collector_extended.py (1)
420-475: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winMissing test for
_INFRA_MAX_DEPTHtruncation.The manifest suite has
test_depth_cap_drops_deep_paths_and_marks_partialcovering_MANIFEST_MAX_DEPTH, but there's no analogous test for_INFRA_MAX_DEPTH(only the count cap andtruncatedpropagation are exercised for infra). Since the collector intentionally sets a different depth cap for.tf(deeper subtrees), a dedicated test would guard that behavior.✅ Suggested additional test
def test_infra_depth_cap_drops_deep_paths_and_marks_infra_partial(self, monkeypatch): """深さ上限超の .tf は落とし infra_partial=True にすること(D10 / D9 c/d)。""" monkeypatch.setattr(github_collector, "_INFRA_MAX_DEPTH", 2) _decls, _imported, _partial, infra, infra_partial, fetched = ( self._patched_collect_full( ["main.tf", "a/b/c/main.tf"], False, file_contents={"main.tf": 'provider "aws" {}\n'}, ) ) assert fetched == ["main.tf"] assert infra_partial is True🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/tests/test_github_collector_extended.py` around lines 420 - 475, Add a dedicated infra depth-cap test alongside the existing collector tests: in test_github_collector_extended.py, extend the GitHub collector coverage for _INFRA_MAX_DEPTH by monkeypatching github_collector._INFRA_MAX_DEPTH, calling _patched_collect_full with one shallow .tf and one deeper .tf path, and asserting the deep path is dropped from fetched while infra_partial becomes True. Keep the test aligned with the existing depth-cap style used for _MANIFEST_MAX_DEPTH so the collector’s .tf-specific depth behavior is guarded.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@backend/app/services/intelligence/github_collector.py`:
- Around line 182-212: The new IaC fetch loop in github_collector.py is still
doing one await per path, which can add many sequential GitHub round-trips
alongside the existing manifest and source loops. Update the fetch flow around
fetch_repo_file, parse_infra, and the selected_infra iteration to use bounded
concurrency (for example with asyncio.gather plus a semaphore) so multiple files
can be fetched in parallel without exceeding rate-limit safeguards. Keep the
existing selection caps and partial-tracking behavior intact while applying the
same pattern consistently across the manifest, source, and infra fetch loops.
In `@backend/tests/test_github_collector_extended.py`:
- Around line 420-475: Add a dedicated infra depth-cap test alongside the
existing collector tests: in test_github_collector_extended.py, extend the
GitHub collector coverage for _INFRA_MAX_DEPTH by monkeypatching
github_collector._INFRA_MAX_DEPTH, calling _patched_collect_full with one
shallow .tf and one deeper .tf path, and asserting the deep path is dropped from
fetched while infra_partial becomes True. Keep the test aligned with the
existing depth-cap style used for _MANIFEST_MAX_DEPTH so the collector’s
.tf-specific depth behavior is guarded.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 706919be-3309-4234-bd7e-e4582a0044af
📒 Files selected for processing (16)
backend/app/schemas/github_skill.pybackend/app/services/intelligence/github_collector.pybackend/app/services/intelligence/github_link_service.pybackend/app/services/intelligence/skills/__init__.pybackend/app/services/intelligence/skills/aggregator.pybackend/app/services/intelligence/skills/infra/__init__.pybackend/app/services/intelligence/skills/infra/base.pybackend/app/services/intelligence/skills/infra/registry.pybackend/app/services/intelligence/skills/infra/terraform.pybackend/app/services/intelligence/skills/types.pybackend/tests/test_github_collector_extended.pybackend/tests/test_github_skills_api.pybackend/tests/test_skill_aggregator.pybackend/tests/test_skill_infra_parsers.pydocs/adr/0016-github-skill-inference.mdweb/src/api/generated.ts
CodeRabbit 指摘対応。_MANIFEST_MAX_DEPTH と同様に _INFRA_MAX_DEPTH の 深さ上限テストを追加し、深い .tf が fetch から落ち infra_partial が立つことを ガードする(count キャップ・truncated に続く D10 / D9(c)(d) の網羅)。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ae3B21DsBFV7ev8SozSYt9
Terraform/OpenTofu の .tf から provider(AWS/Google 等)と resource(具体 サービス。aws_s3_bucket 等)を抽出し、kind=infra / signal_source=infra_declared として 3 層モデルへ投入する。当初「検討中/未採用」だった将来課題を機械検出に
限定して採用(D10)。表示名の human-in-the-loop 畳み込みは別 PR。
kind/signal_source/ecosystem は既存 String カラムの値域内のため migration 不要。 既存 language/package 検出・unique_skills・API 契約は不変。
Claude-Session: https://claude.ai/code/session_01Ae3B21DsBFV7ev8SozSYt9
変更概要
セルフレビューチェックリスト
必須確認
make ciが pass している(lint + test + build-web)条件付き確認(該当する場合のみ N/A と記入)
app/schemas/またはapp/routers/を変更した場合:make codegen-typesを実行しweb/src/api/generated.tsの差分をコミットしたnix develop --command bash -c "cd web && npm run test:e2e")env_keys.py/docs/api.md/infra/modules/cloud_run/main.tf/docker-compose.ymlの 4 箇所を同期したweb/src/で日本語メッセージをweb/src/constants/messages.tsの定数経由で参照した(リテラル直書きなし)破壊的変更
ADR(設計判断を伴う変更の場合のみ)
PR タイトル形式:
<type>: <内容>(日本語)type:
feat/fix/docs/refactor/test/chore/infraSummary by CodeRabbit
New Features
.tf) with provider/resource granularity.Bug Fixes
Documentation